define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zjcaiwuluru/index' + location.search,
                    add_url: 'zjcaiwuluru/add',
                    edit_url: 'zjcaiwuluru/edit',
                    del_url: 'zjcaiwuluru/del',
                    multi_url: 'zjcaiwuluru/multi',
                    import_url: 'zjcaiwuluru/import',
                    table: 'zjcaiwuluru',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search:false,
                showToggle: false,
                showColumns: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'year', title: __('Year'), operate: 'LIKE'},
                        {field: 'yue', title: __('Yue'), operate: 'LIKE'},
                        {field: 'yongjin', title: __('Yongjin'), operate: false},
                        {field: 'wangfei', title: __('Wangfei'), operate: false},
                        {field: 'yiji', title: __('Yiji'), operate: false},
                        {field: 'ru_other', title: __('Ru_other'), operate: false},
                        {field: 'zhanghao', title: __('Zhanghao'), operate: false},
                        {field: 'gz', title: __('Gz'), operate: false},
                        {field: 'zhi_other', title: __('Zhi_other'), operate: false},
                        {field: 'dg_shouru', title: __('Dg_shouru'), operate: false},
                        {field: 'islock', title: __('Islock'), searchList: {"0":__('Islock 0'),"1":__('Islock 1')}, formatter: Table.api.formatter.normal},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('锁表'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('锁表'),
                                    title: __('锁表'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'zjcaiwuluru/locktb?id={id}',
                                    confirm: '锁定后客服无法再修改，确认锁表',
                                    success: function (data, ret) {
                                        //Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        Layer.alert(ret.msg);
                                        location.reload();
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons, operate: false
                        },
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
